package com.heal.controller;

import com.heal.entity.BusinessException;
import com.heal.entity.User;
import com.heal.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserHandler {

  @Autowired private UserService userService;

  @GetMapping("/findAll")
  public List<User> findAll() {
    return userService.findAll();
  }

  @PostMapping
  public void saveUser(@RequestBody User user) {
    userService.saveUser(user);
  }

  @GetMapping("/{name}")
  public User findByName(@PathVariable String name) {
    return userService.findByName(name);
  }

  @GetMapping("/test")
  public void test() throws Exception {

    throw new BusinessException("错误了");
  }
}
